package com.huasoft.servlet.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huasoft.dao.UserDao;

public class AddUserServlet {
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String loginname = request.getParameter("loginname");
		String password = request.getParameter("password");
		String username = request.getParameter("name");
		Integer age;
		if ("".equals(request.getParameter("age"))) {
			age = null;
		} else {
			age = Integer.parseInt(request.getParameter("age"));
		}
		String gender = request.getParameter("gender");
		System.out.println(gender);
		String birthday = request.getParameter("birthday");
		Integer deptid = Integer.parseInt(request.getParameter("deptid"));
		Integer roleid = Integer.parseInt(request.getParameter("roleid"));
		UserDao userDao = new UserDao();
		boolean save = userDao.save(loginname, password, username, age, gender,
				birthday, deptid, roleid);
		if (save) {
			request.setAttribute("msg_addUserSuccess", "增加用户成功");
		} else {
			request.setAttribute("msg_addUserFalse", "增加用户失败");
		}
		request.getRequestDispatcher("/index.jsp").forward(request, response);

	}
}
